
package protocol.transactions;

import protocol.XoneProtocol;
import protocol.XoneServiceCode;

import com.google.gson.JsonElement;
import com.netease.http.THttpRequest;
import com.netease.pkgRelated.ErrorToString;

public class GetCaptchaTrasaction extends EncryptBaseTransaction {

    int mGetType;
    String mPhoneNumber;

    public GetCaptchaTrasaction(int getType, String phoneNumber) {
        super(TRANSACTION_TYPE_GET_CELLPHONE_CAPTCHA);
        mGetType = getType;
        mPhoneNumber = phoneNumber;
    }
    @Override
    protected void onXoneTransactionSuccess(int code, Object obj) {
        if(obj !=null && obj instanceof JsonElement) {
            JsonElement json = (JsonElement) obj;
            String mobileCode = json.getAsJsonObject().get("mobileCode").getAsString();
            notifyMessage(XoneServiceCode.TRANSACTION_SUCCESS,mobileCode);
        }else {
            notifyError(XoneServiceCode.ERR_CODE_DATA_PARSE_EXCEPTION,
                    ErrorToString.getString(XoneServiceCode.ERR_CODE_DATA_PARSE_EXCEPTION));
        }
    }

    @Override
    void realOntransact() {
        THttpRequest request = XoneProtocol.getInstance().createGetCaptcha(mGetType,
                mPhoneNumber);
        sendRequest(request);
    }

}
